﻿using System;
using Castle.Windsor;

namespace VideoSeller.Core.Configuration
{
	public static class IoC
	{
		internal static IWindsorContainer GlobalContainer { get; set; }

		public static IWindsorContainer Container
		{
			get
			{
				var container = GlobalContainer;

				if (container == null)
				{
					throw new InvalidOperationException("The container has not been initialized! Please call IoC.Initialize(container) before using it.");
				}

				return container;
			}
		}

		public static void Initialize(IWindsorContainer windsorContainer)
		{
			GlobalContainer = windsorContainer;
		}

		public static T Resolve<T>()
		{
			return Container.Resolve<T>();
		}
	}
}